package com.kaliterre.kalidroid.service;

import android.app.AlertDialog;
import android.app.Notification;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;

import com.kaliterre.kalidroid.broadcastreceiver.PhoneCallReceiver;
import com.kaliterre.kalidroid.broadcastreceiver.PowerConnectionReceiver;
import com.kaliterre.kalidroid.dal.SettingsDAL;
import com.kaliterre.kalidroid.entity.Settings;

/**
 * @author FIL A2 - Alyssa Boucher, Maxime Bureau, Yohan Mercier, Nicolas Mortier, Zakaria Oualkadi.
 *
 */
public class SondesService extends Service {

	private PowerConnectionReceiver powerBatteryBroadcast;
	private PhoneCallReceiver phoneCallBroadcast;

	/* (non-Javadoc)
	 * @see android.app.Service#onBind(android.content.Intent)
	 */
	@Override
	public IBinder onBind(Intent intent) {
		// TODO Auto-generated method stub
		return null;
	}

	/* (non-Javadoc)
	 * @see android.app.Service#onCreate()
	 */
	public void onCreate() {

		Log.i("", "************************ START ************************");

		super.onCreate();

		this.powerBatteryBroadcast = new PowerConnectionReceiver();
		this.phoneCallBroadcast = new PhoneCallReceiver();
		
        SettingsDAL settingsDal = new SettingsDAL(this);
        settingsDal.open();
        
        Settings settings = new Settings();
        settings = settingsDal.retrieveSettings();
        if(settings.isActiveBatterySonde()) this.registerReceiver(this.powerBatteryBroadcast, this.powerBatteryBroadcast.getIntentFilterActions());
        if(settings.isActiveCallSonde()) this.registerReceiver(this.phoneCallBroadcast, this.phoneCallBroadcast.getIntentFilterActions());
		settingsDal.close();
	}

	/* (non-Javadoc)
	 * @see android.app.Service#onDestroy()
	 */
	public void onDestroy() {

		Log.i("", "************************ STOP ************************");
		super.onDestroy();

		this.unregisterReceiver(this.powerBatteryBroadcast);
		this.unregisterReceiver(this.phoneCallBroadcast);
		
	}

}
